// import { Page } from "@/types/storeModule"
import { assign } from 'lodash-es'

const state = {
  // 接口调用参数
  params: {
    page: {
      currentPage: 1,
      pageSize: 20,
      totalCount: 0,
      totalPage: 0,
      sortField: 'd.type',
      order: 'asc'
    },
    options: {}
  },
  roles: {}, // 权限
  apiName: 'backMenu',
  privileges: ['dic_add', 'dic_export', 'dic_import'],
  // 列表data数据
  isLoading: false,
  tableData: [],
  searchData: [
    {
      id: 'keyword',
      name: '类型、描述',
      type: 'text',
      hint: '类型、描述',
      defaultValue: ''
    },
  ],
  tableHeadList: [
    {
      label: '类型',
      prop: 'type',
      width: 120
    },
    {
      label: '描述',
      prop: 'des',
      width: 200
    },
    {
      label: '状态',
      prop: 'proxyStatus',
      width: 80,
      slotName: 'proxyStatus'
    },
    {
      label: '更新时间',
      prop: 'updateTime',
      width: 200
    },
    {
      label: '更新人',
      prop: 'updater',
      width: 80
    }
  ]
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
  // 更新页面搜索内容
  updateSearchData(state, payload: any[]) {
    state.searchData = payload
  },
  // 更新表格 loading 状态
  updateLoading(state, payload: boolean) {
    state.isLoading = payload
  },

  // 更新数据page
  updatePage(state, payload: any) {
    state.params.page = assign(state.params.page, payload)
  },

  // 更新数据Condition
  updateCondition(state, payload: any) {
    state.params.condition = cloneDeep(payload)
  },

  // 更新data数据
  updateTableData(state, payload: any[]) {
    state.tableData = payload
  },
  // 更新列表表头数据
  updateEditTableList(state, payload: any[]) {
    state.tableHeadList = payload
  },
  // 更新列表参数数据
  updateParams(state, payload: any) {
    state.params = Object.assign({}, state.params, payload)
  },
  // 更新权限
  updateRoles(state, payload: Record<string, boolean>) {
    state.roles = payload
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
